/*
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2014
 *
 * fileName:  CrossSiteScriptFilter.java
 * author:  lei
 * Company:  Cloudland Studio
 * Createdate:  2013-9-14 上午11:21:42
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2013-9-14          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.cloudland.web.context.request.XSSCheckRequest;

 /**
 * <pre> 
 * 过滤 脚本注入攻击。
 * </pre>
 * @ClassName  CrossSiteScriptFilter
 * @author  lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class CrossSiteScriptFilter implements Filter {

	/**
     * LOGGER 日志对象
     */
    private static final Logger LOGGER = Logger.getLogger(CrossSiteScriptFilter.class);
    
    /**
     * @param filterConfig
     * @throws ServletException
     */
    public void init(FilterConfig filterConfig) throws ServletException {
    	if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("CrossSiteScriptFilter initialization method is not implemented.");
		}
    }
    
    /**
     * @param request
     * @param response
     * @param chain
     * @throws IOException
     * @throws ServletException
     */
    public void doFilter(ServletRequest request, ServletResponse response,
    		FilterChain chain) throws IOException, ServletException {
    	
    	if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("CrossSiteScriptFilter filter begins processing...");
        }
        
        // 过滤 XSS 攻击
        chain.doFilter(new XSSCheckRequest((HttpServletRequest)request), response);
    }
    
    /**
     * 
     */
    public void destroy() {
    	if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("CrossSiteScriptFilter destruction method is not implemented.");
		}
    }
}
